package com.softeem.blog.dao;

import java.util.List;

import com.softeem.blog.entity.Banner;
import com.softeem.blog.utils.DBUtils;

public class BannerDAO implements IBaseDAO<Banner>{

	@Override
	public boolean insert(Banner t) {
		String sql = "insert into banner(title,summary,path,sort) values(?,?,?,?)";
		return DBUtils.exeUpdate(sql, t.getTitle(),t.getSummary(),t.getPath(),t.getSort());
	} 

	@Override
	public boolean deleteById(int id) {
		String sql = "delete from banner where id=?";
		return DBUtils.exeUpdate(sql, id);
	}

	@Override
	public boolean update(Banner t) {
		String sql = "update banner set title=?,summary=?,path=? where id=?";
		return DBUtils.exeUpdate(sql, t.getTitle(),t.getSummary(),t.getPath(),t.getId());
	}

	@Override
	public Banner findById(int id) {
		String sql = "select * from banner where id=?";
		return DBUtils.queryOne(Banner.class, sql, id);
	}

	@Override
	public List<Banner> findByPage(int pageSize, int pageNow) {
		String sql = "select * from banner limit ?,?";
		return DBUtils.queryList(Banner.class, sql, (pageNow - 1) * pageSize,pageSize);
	}

	@Override
	public int getCount() {
		String sql = "select count(*) from banner";
		return DBUtils.queryCount(sql);
	}

}
